<#import "../../common/layout.ftl" as l>


<@l.content>

<form id="pagination-form" method="post" class="form-inline">

    <#--<input type="hidden" name="page" value="${pageInfo.pageNum}">-->
    <#--<input type="hidden" name="limit" value="${pageInfo.pageSize}">-->
    <#--<input type="hidden" name="totalPage" value="${pageInfo.pages}">-->
    <div class="ibox">
        <div class="ibox-content">
                <div class="form-group">
                    <div class="input-group search-content">
                        <input id="gzname" type="text"   class="form-control" placeholder="请输入分组名">
                        <span class="input-group-btn">
                        <input id="addGroup" type="button" class="btn btn-primary" value="添加">
                        </span>
                    </div>
                </div>


            <div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover dataTables-example" >
                        <thead>
                        <tr>
                            <th>组名</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                            <#list guanZhuList as gz>
                            <tr>
                                <td><#if gz.name??>${gz.name}<#else></#if></td>
                                <td><a onclick="deleteGroup('${gz.id}')" href="#">删除</a></td>
                            </tr>
                            </#list>
                        </tbody>


                    </table>
                </div>
                <div class="pagination-content">
                    <div id="pagination" class="pagination">
                    </div>
                </div>
            </div>
        </div>

    </div>
</form>


</@l.content>

<script src="/pagination/js/pagination.js"></script>

<script>
    $(document).ready(function () {
        $("#addGroup").click(function () {
            var gzname = $("#gzname").val();
            if(gzname == null||gzname==""){
                layer.msg("必填项不可为空！");
                return;
            }
            $.ajax({
                url:"/ship/guanzhu/insertGZ?gzname="+gzname,
                type:"POST",
                success:function (data) {
                    if(data){
                        layer.msg("添加成功！");
                      setTimeout(function () {
                          location.reload();
                      },500);
                    }else{
                        layer.msg("名称已存在！");
                    }
                }
            })

        })
    })

    function deleteGroup(id) {

        layer.confirm('是否确认删除该组别？（提醒：该组别下的关注船舶将一并删除）', {
            btn: ['确认','取消'] //按钮
        }, function(){
            $.ajax({
                url:"/ship/guanzhu/deleteGZ?gzid="+id,
                type:"POST",
                success:function (data) {
                    if(data){
                        layer.msg("删除成功");
                        setTimeout(function () {
                            location.reload();
                        },500);
                    }else{
                        layer.msg("删除失败");
                    }
                }
            })
        }, function(){

        });

    }
</script>